﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Data.SqlClient;
using System.Configuration;
using MySql.Data.MySqlClient;

namespace WaveMaster.Holidays.Club.Service
{
    public class LogService : IService
    {
        public static void WriteLog(string log)
        {
            bool isLog = Convert.ToBoolean(ConfigurationManager.AppSettings["islog"]);
            if (!isLog) return;
            string m_logPath = ConfigurationManager.AppSettings["logPath"];
            string fileName = m_logPath + DateTime.Today.ToString("ddMMyyyy") + "_WMHC_Log.txt";
            if (!File.Exists(fileName))
            {
                FileStream fs = File.Create(fileName);
                fs.Close();
            }
            StreamWriter sw = File.AppendText(fileName);
            sw.WriteLine(DateTime.Now.ToString() + " - " + log);
            sw.Close();
        }
        public static void WriteLogExecuteSQL(string sql)
        {
            WriteLog("Execute SQL :" + sql);
        }
        //public static void WriteLogExecuteSQLCommand(MySqlCommand sql)
        //{
        //    WriteLog("Execute SQL [" + sql.Connection.Database +"] : "+ sql.CommandText);
        //}
        public static void WriteLogException(Exception exception)
        {
            WriteLog("Exception [" + exception.GetType().ToString() + "] : " + exception.Message);
            if (exception.InnerException != null)
                WriteLogException(exception.InnerException);
        }
    }
}
